//https://leetcode.cn/problems/n-ary-tree-level-order-traversal/submissions/589244983/
class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        if (root == nullptr) return {};
        vector<vector<int>> ans;
        vector<Node*> cur = { root };
        while (cur.size()) {
            vector<Node*> nxt;
            vector<int> vals;
            for (auto node : cur) {
                vals.push_back(node->val);
                nxt.insert(nxt.end(), node->children.begin(), node->children.end());
            }
            ans.emplace_back(vals);
            cur = move(nxt);
        }
        return ans;
    }
};